import 'package:flutter/material.dart';

class CheckboxDemo extends StatefulWidget {
  const CheckboxDemo({super.key});

  @override
  State<CheckboxDemo> createState() => _CheckboxDemoState();
}

class _CheckboxDemoState extends State<CheckboxDemo> {
  List isChecked = [false,false,false];
  List isCheckList = [false,false,false];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('CheckboxDemo'),
        elevation: 0,
      ),
      body: Container(
        padding: const EdgeInsets.all(6),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            CheckboxListTile(
              value: isCheckList[0],
              onChanged: (value) {
                setState(() {
                  isCheckList[0] = value!;
                });
              },
              title: const Text('CheckboxListTitle'),
              subtitle: const Text('Checkbox Item A'),
              secondary: const Icon(Icons.bookmark),
              selected: isCheckList[0],
            ),
            CheckboxListTile(
              value: isCheckList[1],
              onChanged: (value) {
                setState(() {
                  isCheckList[1] = value!;
                });
              },
              title: const Text('CheckboxListTitle'),
              subtitle: const Text('Checkbox Item B'),
              secondary: const Icon(Icons.bookmark),
              selected: isCheckList[1],
            ),
            CheckboxListTile(
              value: isCheckList[2],
              onChanged: (value) {
                setState(() {
                  isCheckList[2] = value!;
                });
              },
              title: const Text('CheckboxListTitle'),
              subtitle: const Text('Checkbox Item C'),
              secondary: const Icon(Icons.bookmark),
              selected: isCheckList[2],
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Checkbox(
                  isError: true,
                  value: isChecked[0],
                  onChanged: (value) {
                    setState(() {
                      isChecked[0] = value;
                    });
                  },
                  activeColor: Colors.amber,
                ),
                Checkbox(
                  isError: true,
                  value: isChecked[1],
                  onChanged: (value) {
                    setState(() {
                      isChecked[1] = value;
                    });
                  },
                  activeColor: Colors.amber,
                ),
                Checkbox(
                  isError: true,
                  value: isChecked[2],
                  onChanged: (value) {
                    setState(() {
                      isChecked[2] = value;
                    });
                  },
                  activeColor: Colors.amber,
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}